package web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import beans.Likes;
import beans.Member;
import service.LikesService;
import service.MemberService;
import serviceimpl.LikesServiceIpmt;
import serviceimpl.MemberServiceIpmt;

@WebServlet("/LikeServlet")
public class LikeServlet extends HttpServlet {
	private MemberService ms=new MemberServiceIpmt();
	private LikesService ls=new LikesServiceIpmt();
	private Likes likes=new Likes();
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		Member likeMember = (Member) session.getAttribute("othermember");
		Member member = (Member) session.getAttribute("member");
		
		likes.setUsername(member.getUsername());
		likes.setLikeusername(likeMember.getUsername());
		
		ls.likes(likes);
		if(likes.getStatus()==1) {
			ms.like(likeMember);
		}else {
			ms.unLike(likeMember);
		}
		session.setAttribute("likasStatus", likes.getStatus());
		response.sendRedirect("/zzLoveProduct/home/otherhome.jsp");
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}